<template>
	<view>
		<view class="search-bar">
			<uni-search-bar radius="5" placeholder="请输入企业名称" clearButton="always" cancelButton="none"
				@input="getList" />
		</view>
		<view class="search-content">
			<view class="search-content-item" v-for="item,index in pageData" :key="index"  @tap="handleSelect(item.NAME)">
				<image src="../../static/images/info_icon_01.png" mode="widthFix" class="search-content-item-img">
				</image>
				<text class="search-content-item-text">{{item.NAME}}</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				companyData: [],
				pageData: []
			}
		},
		methods: {
			async getData() {
				uni.showLoading({

				})
				const res = await this.$req({
					url: 'info/busEnterprise/getName.do',
					data: {}
				})
				uni.hideLoading()
				if (res.data.success) {
					this.companyData = res.data.data
				} else {
					uni.showToast({
						title: '请求公司数据错误',
						icon: 'none'
					})
				}
			},
			getList(e) {
				console.log('e', e)
				if (!e) {
					this.pageData = []
					return;
				}
				const data = [...this.companyData]
				const ret = data.filter(item => {
					return item.NAME.indexOf(e) != -1
				})
				this.pageData = ret;
			},
			handleSelect(name) {
				console.log('name', name)
				uni.$emit("companyName", {
					data: name
				});
				uni.navigateBack({

				})
			}
		},
		onLoad() {
			this.getData()
		}
	}
</script>

<style lang="scss" scoped>
	.search-bar {
		background: #FFFFFF;
		width: 100%;
		padding: 6rpx 20rpx;
		border-bottom: 10rpx solid rgba(232, 240, 242, 1);
	}

	.search-content {
		background: #fff;
		padding: 30rpx 0 30rpx 0;
	}

	.search-content-item {
		display: flex;
		align-items: center;
		height: 24rpx;
		padding: 20rpx 48rpx;
		margin-bottom: 30rpx;

	}

	.search-content-item-img {
		width: 24rpx;
		margin-right: 10rpx;
	}

	.search-content-item-text {
		color: #333;
		font-size: 26rpx;
	}
</style>
